-
-
1import pygame import sys from pygame.time import Clock pygame.init() screen = pygame.display.set_mode((1080,960)) screen.fill((230,230,230)) pygame.display.set_caption('测试') image2 = pygame.image.load('background.jpg') background = pygame.transform.scale(image2,(1080,960)) FPS= 60 clock = pygame.time.Clock() class Enemy(pygame.sprite.Sprite): def __init__(self): super(Enemy,self).__init__() self.image = pygame.image.load('enemy.jpg') self.rect = self.image.get_rect(top=0,left=500) def move(self): self.rect.move_ip(0,1) class Player(pygame.sprite.Sprite): def __init_
-
1surface里的convert()是什么作啊? pygame.image.load()返回值不就是一个surface吗,为啥还要用convert()? 看了官方的文档,说:This is always the fastest format for blitting. It is a good idea to convert all Surfaces before they are blitted many times. 没能懂这句话,为啥会更快?
-
2
-
0
-
12import pygame from settings import Settings from ship import Ship import game_functions as gf def run_game(): #初始化背景设置 pygame.init() ai_settings = Settings() #显示窗口大小 screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) #标题 pygame.display.set_caption("Alien Invasion") ship = Ship(screen) while True: gf.check_events(ship) ship.update() gf.update_screen(ai_settings, screen, ship) run_game() class Settings(): def __init__(self): self.screen_width = 800 self.screen_height = 600 self.bg_color = (230, 230, 230) import pygame
-
11
-
0一段把1個Surface的某RGB顏色轉成另一顏色的code import pygame pygame.init() win=pygame.display.get_desktop_sizes()[0] ww=win[0] wh=win[1] screen = pygame.display.set_mode((ww/2,wh/2),pygame.NOFRAME) clock = pygame.time.Clock() fontlist=pygame.font.get_fonts() font=pygame.font.Font(None,12) pic = pygame.Surface((16,16)) #這行做了一個16*16的Surface pic.fill((255,255,255)) #油白了 screen.blit(pic,(0,0))#先看看.... s=pygame.image.tobytes(pic, 'RGBX' ) #把pic轉為32 bit格式的byte object,想省記憶體的可以用RGB省1/3.... #就是1張2048*2048的圖省4M..
-
0pygame用sysfont在display表現的小程式 剛開始學時我fontlist中大部份字型連0x32到0x7e都是四方框出不了字...一個一個試了由0試到27個才有1個能用的......吃透了後寫這程式竟然告訴我0x32到0x7e大部分字體都正常24號還能用中文......田字顯示不了的就是那字體沒中文,漢字字型了.... 要裝了pygame才能跑! https://pan.baidu.com/s/19wwSom5T-sXd032gPSgq2Q?pwd=mypm ---以下是源碼---- import pygame import os pygame.init() win=pygame.display.get_desktop_sizes()[0] ww=win[0] wh=win[1] i=1 screen = pygame.display.set_mode(
-
1
-
3import pygame import random pygame.init() disp=pygame.display.Info() ww=disp.current_w wh=disp.current_h win=ww,wh screen = pygame.display.set_mode(win) clock = pygame.time.Clock() ti=0 dx=0 dy=0 dr=0 dg=0 db=0 gx=1 gy=1 def mew(x=0,y=0,r=0,g=0,b=0): pygame.draw.arc(screen,(r,g,b),(x,y+15,10,10),0,6 ) pygame.draw.line(screen,(r,g,b),(x+5,y+15),(x+5,y+25)) pygame.draw.line(screen,(r,g,b),(x,y+20),(x+10,y+20)) pygame.draw.line(screen,(r,g,b),(x+15,y+5),(x+35,y+5)) pygame.draw.line(screen,(r,g,b),(x+20,y),(x+20,y+10)) pygame.draw.line(screen,(r,g,b),(x+30,y),(x+30,y+10)) pygame.draw.arc(screen,(r
-
5110如题,自己有一套关于实战项目的课件(20多个小游戏吧),现在还需要一套讲基础知识的课件(比如draw函数绘制几何图形,surface的性质,等等) 有的朋友能不能分享一下,谢谢。 当然,也不排斥其它类型的课件,可以互相交换交流一下,多多益善。3715我在一个文件定义了一个PlayerS类 然后在游戏主文件调用了它的其中一个方法 如下 然后是主程序中用到的地方 目的是在玩家不同状态下播放不同动画 但是这样就会报错 我知道这是因为pyhton将我的 self.statement识别成要调用PlayerS的一个属性 但是我的本意是想把参数中的statement当成一个变量在函数中使用。 求求吧里的大佬这种情况该怎么写?8大佬们,pygame到底怎么安装啊590友好交流0有问题进群讨论 记得把问题和代码描述清楚!!!05我写了个方向键控制自机判定点移动的程序,目前可以做到斜向移动,但转回正上下时会静止不动 比如在先按↑再按→进行右上方的运动时,松开↑会正常向右,但是松开→却不会向上而是静止在原地。 求解答0'bullet' object has no attribute 'rect'2大佬们好,我想做个pygame,简单来说就是左右两边对抗,对抗形势比较简单,没有子弹,就是挤,左右两面很多球在互相挤。就可以了。哪位大佬整好在学习pygame 有时间的话 私聊我吧 有偿实现。2奈奈滴,找半天全是一样的,被一段没用的代码绕了一下午艹!1刚做完ikun战机,打个卡先15做起来方便多了51精灵的kill方法,只删除精灵组里面的精灵 精灵本身还在的 这样精灵还是占用内存,需要用del sprite 删除精灵吗?250812就是子弹从子弹发射的初始位置到末位置一定距离后消失,也就是设定它的射程,大概要怎么写啊4import pygame import sys import traceback from pygame.locals import * pygame.init() bg_size = width, height = 600, 600 screen = pygame.display.set_mode(bg_size) def main(): hero = pygame.image.load("images/hero0.png").convert_alpha() x, y = 300, 300 running = True clock = pygame.time.Clock() while running: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() # 检测键盘操作 keys_pressed = pygame.key.get_pressed() if keys_pressed[K_w]: y -= 3 if keys_pressed[K_s]: y += 3 if keys_pressed[K_a]: x -= 3 if keys_pressed[K_d]: x += 3 # 绘制 screen.blit(her3126[图片][图片][图片][图片][图片][图片][图片][图片]程序运行没问题就是看不到左上角绘制的文本和放进去的坦克图片,后面发现改不了color(小白猜测是这个问题)pygame.color后面无论把数字改成什么yanse窗口yanse都不会变,第一个pygame.color后面格式错了是刚改的忘改过来了 之前把窗口颜色改成pygame.Color(255,0,0)窗口yanse还是黑的都没变,求大佬给小白解答下0中文的有吗?官网打开速度太慢了。85链接: https://pan.baidu.com/s/1ikOB18_N4Ah-jk7O3JOseA 提取码: r7m5(我的第一贴呀,老激动了,以至于名字都没改)1我想做一个射击游戏,但是我现在无法让玩家的面部始终朝向我的鼠标 请问有哪位大佬写过类似的类或函数能借我用一下吗?不胜感激1救救孩子吧